<?php
class data_email extends data {
	public function __construct() {
		parent::__construct();
		
	}
	public function send_active_key ($id) {
		$id = intval($id);
		if ($id) {
			$execute = $this->db->execute('
				select
					*
				from
					users_unactived
				where
					id	= "'.$id.'"
			');
			if ($execute) {
				if ($execute[0]['email']) {
					return $this->send_active_key_by_email($execute[0]);
				} elseif ($execute[0]['weibo_id']) {
					return $this->send_active_key_by_weibo($execute[0]);
				}
			} else return false;
		} else return false;
	}
	private function send_active_key_by_email ($execute) {
		if (data_user::is_email($execute['email'])) {
			// 标题
			$title = "uRead.Me 账号激活";
			$subject = "=?UTF-8?B?" . base64_encode($title) . "?=";

			// 头参数
			$headers  = "MIME-Version: 1.0\r\n";
			$headers .= "Content-type: text/html; charset=utf-8\r\n";
			$headers .= "To: ".$execute['email']."\r\n";
			$headers .= "From: recommend@uread.me\r\n";
			$headers .= "Reply-To: recommend@uread.me\r\n";
			
			// 正文
			$html = '
				<div style="display:inline-block; margin:20px; padding:40px; border:1px solid #CCC; background-color:#F5F7F9; font-family:微软雅黑; font-size:14px; line-height:180%;">
					'.(($execute['nickname']) ? $execute['nickname'] : $execute['email']).'，欢迎您加入uRead.Me！<br><br>
					请点击下面的地址激活您的账号：<br>
					<a href="http://uread.me/active.php?code='.$execute['active_key'].'" style="font-family:微软雅黑; font-size:14px;" target="_blank">http://uread.me/active.php?code='.$execute['active_key'].'</a>
					
					<div style="margin-top:40px; border-top:1px dotted #DDD; font-family:Arial; font-size:12px; padding-top:10px; color:#999; line-height:150%;">
						本邮件由uRead.Me系统自动发出，请勿直接回复！
					</div>
				</div>
			';
			return @mail($execute['email'], $subject, $html, $headers);
		} else return false;
	}
	private function send_active_key_by_weibo ($execute) {
		
	}
}
?>